#include "Obs_An.h"
static flag = 1;
void OBS()
{
    float dis, dis2;
    char res;
    res = Ultrasonic_get_distance(&dis);
	
	if (res == 0)
    {
        if (dis < 10)
        {    Light_on(ALL);
					   Buzzer_alarm();
            flag = 0;
            Motors_stop();
            os_wait2(K_TMO,1);
            Motors_translate(30, RIGHT_M);
            os_wait2(K_TMO, 100);
            Motors_backward(30, MID_M);
            os_wait2(K_TMO, 50);
        }
        else
        {    
					Light_off(ALL);
            if (flag == 1)
            {
                Motors_forward(30, MID_M);
            }
            else
            {
                Motors_backward(30, MID_M);
                os_wait2(K_TMO, 5);
                res = Ultrasonic_get_distance(&dis2);
                if (dis == dis2)
                {
                    flag = 1;
                    Motors_translate(30, RIGHT_M);
                    os_wait2(K_TMO, 50);
                }
            }
        }
    }
}
